package com.example.parking.interfaces.http;

import com.example.parking.application.ParkingSpaceService;
import com.example.parking.domain.model.ParkingSpace;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/spaces")
public class ParkingSpaceController {
    private final ParkingSpaceService parkingSpaceService;

    public ParkingSpaceController(ParkingSpaceService parkingSpaceService) {
        this.parkingSpaceService = parkingSpaceService;
    }

    @GetMapping
    public List<ParkingSpace> list(@RequestParam String lotCode) {
        return parkingSpaceService.listByLot(lotCode);
    }

    @GetMapping("/{id}")
    public ParkingSpace get(@PathVariable Long id) {
        return parkingSpaceService.getById(id);
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public ParkingSpace create(@RequestBody ParkingSpace space) {
        return parkingSpaceService.create(space);
    }

    @PutMapping("/{id}")
    public ParkingSpace update(@PathVariable Long id, @RequestBody ParkingSpace space) {
        return parkingSpaceService.update(id, space);
    }

    @DeleteMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void delete(@PathVariable Long id) {
        parkingSpaceService.delete(id);
    }
}


